package com.managerplat.jms;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;

import com.managerplat.model.DishInfo;
import com.managerplat.model.OrderInfo;
import com.managerplat.model.Orders;
import com.managerplat.source.Resources;

public class ProducerTest {
	@Test
	public void queueProducer() throws JMSException {
		String brokerURL = Resources.brokerURL;
		ConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL);
		Connection conn = factory.createConnection();
		conn.start();
		
		Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		
		Queue queue = session.createQueue("user_msg23");
		
		MessageProducer producer = session.createProducer(queue);
		
		List<OrderInfo> listOrder = new ArrayList<OrderInfo>();
		
		listOrder.add(new OrderInfo(2,21,10,1,"xxxaddr"));
		listOrder.add(new OrderInfo(2,21,13,1,"xxxaddr"));
		listOrder.add(new OrderInfo(2,22,10,1,"xxxaddr"));
		Orders orders = new Orders();
		orders.setList(listOrder);
		// int userId, int sellerId, int dishId, int count, String userAddr
		//ObjectMessage objectMessage = session.createObjectMessage((Serializable) orders);
		TextMessage message = session.createTextMessage("I am Producer!");
		//producer.send(objectMessage);
		for(int i=0;i<10;i++)
		{
			producer.send(message);
		}
		
		
		conn.stop();
		conn.close();
		System.out.println("end.....!");
	}
}
